﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine;
using Engine.Components.Arithmetic;
using Engine.Components.CompArch;

using NUnit.Framework;

namespace Engine.Tests
{
	[TestFixture]
	public class TestSingleComponentAdder1
	{
		private IntegerAdder adder1;

		[SetUp]
		public void Setup()
		{
			adder1 = new IntegerAdder();
		}

		[Test]
		public void AdderZeroTest()
		{
			Assert.IsTrue(adder1.Result.Value == 0);
		}

		[Test]
		public void AdderOneInputTest()
		{
			adder1.Op1.Value = 208;
			int x = adder1.Result.Value;

			Assert.IsTrue(x == 208);
		}

		[Test]
		public void AdderNormalTest()
		{
			adder1.Op1.Value = 2;
			adder1.Op2.Value = 3;
			int x = adder1.Result.Value;

			Assert.IsTrue(x == 5);
		}

		[Test]
		public void AdderEnumPortsTest()
		{
			IInPort[] iports = adder1.GetInPorts();
			IOutPort[] oports = adder1.GetOutPorts();

			Assert.IsTrue(iports.Length == 2);

			Assert.IsTrue(iports[0].GetGenericType() == typeof(int));
			Assert.IsTrue(iports[1].GetGenericType() == typeof(int));

			Assert.IsTrue(oports.Length == 1);
			Assert.IsTrue(oports[0].GetGenericType() == typeof(int));
		}
	}
}
#if true

namespace Engine.Tests
{

	[TestFixture]
	public class TestSingleComponentMemoryBank
	{
		private MemoryBank mem;

		[SetUp]
		public void Setup()
		{
			mem = new MemoryBank();
            mem.Alignment.Value = AlignmentBoundary.ByteAddressable;
		}

		[Test]
		public void MemoryBankWriteThenReadTest()
		{
			mem.Address.Value = 100;
            byte[] singlebyte = { 128 };
			mem.WritePort.Value = singlebyte;
            mem.IsWrite.Value = true; // locks in the write
			mem.IsWrite.Value = false; // forces a read
			Assert.IsTrue(mem.ReadPort.Value[0] == 128);
			Assert.IsFalse(mem.InvalidAddressFlag.Value);
		}

		[Test]
		public void MemoryBankInvalidAddressTest()
		{
			mem.Address.Value = 300;
			Assert.IsTrue(mem.InvalidAddressFlag.Value);
		}

		[Test]
		public void ChangeMemoryConfigurationTest()
		{
            mem.Alignment.Value = AlignmentBoundary.HalfWordAddressable;
            mem.Size = 1024;
		}
	}
#endif
}
